import path from 'path'


export let isNull = (data) => {
    if(!data) return true;
    if(JSON.stringify(data) == '{}') return true;
    if(JSON.stringify(data) == '[]') return true;
    return false
}



export let getMenus = (routes, basePath = '') => {
    let result = []

    routes.forEach((item)=>{
        if(isNull(item.meta) && isNull(item.children)) return

        if(isNull(item.meta) && !isNull(item.children)){
            result.push(...getMenus(item.children))
            return
        }

        let routePath = path.resolve(basePath, item.path)
        // console.log(routePath);

        let route = find((m, i) => {m.path == routePath})

        if(!route){
            route = {
                ...item,
                path: routePath,
                children: []
            }
            if(route.meta.title && route.meta.icon){
                result.push(route)
            }
        }
        if(item.children){
            route.children.push(...getMenus(item.children, route.path))
        }
    })
    // console.log(result);
    return result
}   